package com.fs.ibox.dao.impl;

import com.fs.ibox.dao.OrdersDao;
import com.fs.ibox.pojo.Orders;
import com.fs.ibox.util.DateUtil;
import com.fs.ibox.util.JDBCUtil;

import java.util.List;

public class OrdersDaoimpl implements OrdersDao {
    //增加市场订单记录
    @Override
    public void addOrdersh(Orders o) {
        String sql = "INSERT INTO tb_orders VALUE(?,?,?,?,?,?,?,?)";
        JDBCUtil.executeUpdate(sql, o.getId(), o.getOrdersId(), o.getUsernameBy(), o.getUsernameSell(), o.getOprice(), o.getCname(), o.getCimg(), o.getOrdertime());
    }

    @Override
    public void addOrders(Orders orders) {
        String sql="INSERT INTO tb_orders (ordersid,usernameby,usernamesell,oprice,cname,cimg,ordertime) VALUES (?,?,?,?,?,?,?)";
        int i = JDBCUtil.executeUpdate(sql, orders.getOrdersId(), orders.getUsernameBy(), orders.getUsernameSell(), orders.getOprice(), orders.getCname(), orders.getCimg(), DateUtil.toString(orders.getOrdertime()) );
    }

    @Override
    public List<Orders> queryOrdersAll() {
        String sql=" SELECT * FROM tb_orders";
        List<Orders> orders = JDBCUtil.executeQuery(sql, Orders.class);
        return orders;
    }

    @Override
    public void delById(int id) {
        String sql="DELETE FROM tb_orders where id=?";
        int i = JDBCUtil.executeUpdate(sql, id);

    }
}
